<!--
 * @Descripttion: 销售管理->派工单
 * @version: V1.0
 * @Author: GaoWei
 * @Date: 2021-05-07 18:40:58
 * @LastEditors: GW
 * @LastEditTime: 2022-06-11 11:29:16
-->
<template>
    <div class="content-wrapper a-base-container">
        <div class="requisition-set-wrapper">
            <!-- 按钮 -->
            <div class="btn-wrapper clearfix">
                <btns-wrapper @searchClick="searchClick" :showModel="showModel" :orderId="orderId" :voucherState="voucherState" :editMask="editMask" @printOrder="printOrder" @switchList="switchList" @submitServer="submitServer" @clickEdit="clickEdit" @deleteOrder="deleteOrder" @getIdByData="getIdByData" @auditClick="auditClick1" @turnThePage="turnThePage" @syncOrder="syncOrder" @submitOrder="submitOrder" @exportDetail="exportDetail" @bgChange="bgChange">
                    <template slot="neworder">
                        <a-dropdown class="btns" key="new" style="display:block">
                            <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                                <a-icon class="btns-icon" type="file-add" />
                                <div class="btns-text">新增
                                    <a-icon type="down" style="color:rgb(24,144,255);vertical-align:middle;" />
                                </div>
                            </a>
                            <a-menu slot="overlay">
                                <a-menu-item key="1">
                                    <a href="javascript:void(0)" @click="newForecast">选生产订单</a>
                                </a-menu-item>
                            </a-menu>
                        </a-dropdown>
                    </template>
                    <!-- <template slot="shengdan">
                        <div class="btns-disable">
                            <a-dropdown class="btns" key="sheng" style="display:block">
                                <a class="ant-dropdown-link" @click="e => e.preventDefault()">
                                    <a-icon class="btns-icon" type="snippets" />
                                    <div class="btns-text">生单
                                        <a-icon type="down" />
                                    </div>
                                </a>
                            </a-dropdown>
                        </div>
                    </template> -->
                </btns-wrapper>
            </div>

            <div ref="print" class="credentials-wrapper documents-wrapper" id="documents-wrapper">
                <h3 class="text-center"><span class="text-name">派工单</span><br /></h3>
                <a-row>
                    <a-col :span="24">
                        <section>
                            <div>
                                <span class="audit-status" style="z-index: 78" v-show="voucherState == 0">待审核</span>
                                <span class="audit-status" style="z-index: 78" v-show="voucherState == 1">已审</span>
                            </div>
                            <a-form-model :layout="formLayout">
                                <!-- 遮罩（点击修改关闭遮罩） -->
                                <!-- <div class="edit-mask-header" v-show="editMask"></div> -->

                                <div class="header-box" style="positon:relative" ref="hederHeight">
                                    <div class="divFixed" :style="{height:(hederHeight+'px')}" v-show="editMask"></div>
                                    <a-row class="order-dynamic-form-wrapper">
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="派工单编号" :rules="[{ required: true, message: '', trigger: 'input' },]">
                                                <a-input :disabled="true" v-model="dataJson.code"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="加工单编号" :rules="[{ required: true, message: '', trigger: 'input' },]">
                                                <a-input :disabled="true" v-model="dataJson.ProcessingOrderNo"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="订单编号">
                                                <a-input :disabled="true" v-model="dataJson.saleOrderCode"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="车间">
                                                <a-input :disabled="true" v-model="dataJson.officeName"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="产品编码">
                                                <a-input :disabled="true" v-model="dataJson.inventoryCode" onkeyup="value=value.replace(/[^\d]/g,'')" @change="handleArchiveChange(1)" @click="handlInputArchives()" style="position: relative; z-index: 50"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="产品名称">
                                                <a-input :disabled="true" v-model="dataJson.inventoryName" @change="handleArchiveChange(2)" @click="handlInputArchives()" style="position: relative; z-index: 50"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="规格型号">
                                                <a-input :disabled="true" v-model="dataJson.inventorySpecification"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="工艺路线">
                                                <a-input :disabled="true" v-model="dataJson.processRouteName"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="bom版本">
                                                <a-input :disabled="true" v-model="dataJson.bomVersion"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="单位">
                                                <a-input :disabled="true" v-model="dataJson.baseUnitName"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="总下达量">
                                                <a-input :disabled="true" v-model="dataJson.baseQuantity"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">

                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="本次下达量" :rules="[{ required: true, message: '', trigger: 'input' },]">
                                                <a-input v-model="dataJson.quantityreleasedThisTime" @blur="numsChange(1)"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="已完成数量">
                                                <a-input :disabled="true" v-model="dataJson.completedQuantity"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="本次下达次数">
                                                <a-input :disabled="true" v-model="dataJson.timesOfRelease"></a-input>
                                            </a-form-model-item>
                                        </a-col>

                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="单据日期" :rules="[{ required: true, message: '', trigger: 'input' },]">
                                                <a-date-picker v-model="dataJson.voucherDate" @change="(val,option)=>onChangeDate(val,option,0)" />
                                            </a-form-model-item>
                                        </a-col>

                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="派工日期" :rules="[{ required: true, message: '', trigger: 'input' },]">
                                                <a-date-picker v-model="dataJson.dispatchDate" @change="(val,option)=>onChangeDate(val,option,1)" />
                                            </a-form-model-item>
                                        </a-col>

                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="预计完成日期">
                                                <a-date-picker v-model="dataJson.expectFinishDate" @change="(val,option)=>onChangeDate(val,option,2)" />
                                            </a-form-model-item>
                                        </a-col>

                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="状态">
                                                <a-input :disabled="true" v-model="dataJson.voucherStateText"></a-input>
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="负责人">
                                                <a-input v-model="dataJson.personInCharge" @click="searchGroup()" :style="styleProcess"></a-input>
                                                <searchGroupHeader ref="employeesRef" :inputValue="dataJson.personInCharge" :componentName="'employees'" @clickItem="searchBackData"></searchGroupHeader>
                                            </a-form-model-item>
                                        </a-col>
                                    </a-row>
                                </div>

                                <div class="table-box">
                                    <a-tabs default-active-key="1" @change="callback">
                                        <a-tab-pane key="1" tab="派工明细">
                                            <div style="position:relative">
                                                <div class="divFixed" style="left:30px" v-show="editMask"></div>
                                                <a-table :row-selection="{selectedRowKeys:selectedRowKeysDetails,onChange:handleChangeDetails,type:'radio'}" :columns="columnsWork" :customRow="dispatchChange" :scroll="{ x: 1000, y: 347 }" :data-source="dataSourceWork" :pagination="false" bordered>
                                                    <template v-if="isRouterAlive" slot="status" slot-scope="text">
                                                        <div>{{text | statusFun}}</div>
                                                    </template>
                                                    <template v-for="col in slotWork" :slot="col" slot-scope="text, record,index">
                                                        <div data-key="">
                                                            <editableCells v-if="isRouterAlive" :dynamicAllData="timeSlotArr" :text="text" :col="col" :index="index" :record="record" @change="onCellChange(index, col, $event)" :dataSource="dataSourceWork" :showTotal="showTotal" />
                                                        </div>
                                                    </template>
                                                </a-table>
                                            </div>

                                        </a-tab-pane>
                                        <!-- <a-tab-pane key="2" tab="物料明细" force-render>
                                            <div style="position:relative">
                                                <div class="divFixed" v-show="editMask"></div>
                                                <a-table id="process_edit_tb" class="atable-edit" :columns="columns" :customRow="customClick" :data-source="dataSource" :pagination="false" bordered :scroll="{ x: 1000, y: 384 }">
                                                    <template v-for="col in editColumnArraya" :slot="col" slot-scope="text, record, index">
                                                        <div data-key="">
                                                            <editableCells v-if="isRouterAlive" :text="text" :col="col" :index="index" :record="record" @change="onCellChange(index, col, $event)" :dataSource="dataSource" />
                                                        </div>
                                                    </template>
                                                </a-table>
                                            </div>
                                        </a-tab-pane> -->
                                    </a-tabs>
                                </div>
                                <div class="footer-box">
                                    <a-row class="order-dynamic-form-wrapper">
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="修改人">
                                                <a-input v-model="dataJson.updateUserName" :disabled="true" />
                                            </a-form-model-item>
                                        </a-col>
                                        <a-col :xs="grid.xs" :sm="grid.sm" :md="grid.md" :lg="grid.lg" :xl="grid.xl" :xxl="grid.xxl">
                                            <a-form-model-item :label-col="labelCol" :wrapper-col="wrapperCol" label="修改时间">
                                                <a-input v-model="dataJson.updateDate" :disabled="true" />
                                            </a-form-model-item>
                                        </a-col>
                                    </a-row>
                                </div>
                            </a-form-model>

                            <template>
                                <searchArchives v-if="maskArchives" ref="searchArchivesRef" :checkType="checkType" :inventoryDomTop="inventoryDomTop" :inventoryDomRight="inventoryDomRight" :inputType="1" :inputVal="inputVal" @closeArchives="closeArchives" @check="checkArchives"></searchArchives>
                                <div class="mask-archives" v-show="maskArchives" @click="closeArchives"></div>
                            </template>

                        </section>
                    </a-col>
                </a-row>
            </div>
            <div class="contextmenu-box">
                <!-- 右键菜单 -->
                <ul v-show="visible" :style="{ left: left + 'px', top: top + 'px' }" class="contextmenu">
                    <!-- <li @click="handleAdd()">新增行</li>
                    <li @click="handleDelete()">删除行</li> -->
                    <!--  <li @click="handleCopy()">复制行</li> -->
                </ul>
            </div>

        </div>

        <!--加载中-->
        <div class="loading-wrapper" v-show="loading">
            <a-spin class="loading-content" tip="加载中..." />
        </div>
        <!--用做横向打印-->
        <div v-html="stylePrint"></div>
        <!-- <print-modal ref="printDom" v-if="printVisible" :incomingPrintData="incomingPrintData" @cancelPrint="cancelPrint"></print-modal> -->

        <!--选加工单-->
        <a-modal v-model="visibleProcessing" @cancel="cancel" @click="ok" :title="'选择生产订单'" :width="1100">
            <section>
                <!--列表-->
                <p>未完成加工单</p>
                <div style="min-height: 230px">
                    <!-- :row-selection="{ selectedRowKeys:selectedRowKeys1, onChange: onSelectChange1,type:'radio' }" -->
                    <a-table v-if="isRouterAlive" :rowClassName="rowClassName" :columns="columnModal1" :data-source="modalList1" :customRow="tableChange1" bordered :pagination="false" :loading="tableShowLoding">

                    </a-table>
                </div>

                <p class="margin-top-10">加工单明细</p>
                <div style="min-height: 230px">
                    <a-table :row-selection="{ columnWidth:30,selectedRowKeys:selectedRowKeys2,onChange: onSelectChange2,type:'radio' }" :columns="columnModal2" :data-source="modalList2" bordered :customRow="tableChange2" :pagination="false">
                    </a-table>
                </div>
            </section>
            <template slot="footer">
                <div>
                    <a-button type="primary" @click="addClick">确认</a-button>
                    <a-button @click="cancel()" class="margin-left-10">关闭</a-button>
                </div>
            </template>
        </a-modal>

        <!--变更工人弹窗-->
        <a-modal title="变更工人" :visible="visibleGr" @ok="handleGrOk" @cancel="handleGrCancel">
            <a-form :label-col="{ span: 8 }" :wrapper-col="{ span: 8 }">

                <a-form-item label="工人">
                    <searchGroupDetail v-if="showWorkModel" ref="searchComponents" :record="{focus:true}" :inputValue="workFrom.name" :componentName="'clubUser'" @clickItem="workChange">
                    </searchGroupDetail>
                    <a-input v-else v-model="workFrom.name" @focus="showWorkModel=true" />
                </a-form-item>

                <a-form-item label="开工日期">
                    <a-date-picker @change="startTimeChange" />
                </a-form-item>

            </a-form>
        </a-modal>

    </div>
</template>
<script>
import editableCell from "./workshop/editTable/EditableCell";
import { save, list, remove, details, examine, } from "@/api/production/processRoute";
import editableCells from "@/components/OrderDynamicForm/EditableCell";
import searchGroupDetail from "@/components/PopUpLayer/searchGroupDetail";  //静态表格明细搜索组
import { getAction } from "@/api/manage";
import { listNotFinishMain, listNotDispatchedDetail, getCode, listLeafDetailByMother, getMaxDispatchTimes, dispatch, getOneByCondition, deleteApi, examines, changeWorkId, agetDetailList, submitOrder } from "@/api/production/productionProcessCard";
import searchArchives from "@/components/OrderDynamicForm/searchArchives";
import { Controlwidth } from "@/utils/antTableComponents";
import FormSearchGroup from '@/components/Form/FormSearchGroup';
import searchGroupHeader from "@/components/PopUpLayer/searchGroupHeader";
import dynamicSearch from "@/components/PopUpLayer/dynamicSearch";
import btnsWrapper from '@/components/OrderDynamicForm/btnsWrapper'
import AntMenu from '../../components/AntMenu/AntMenu（右侧显示）.vue';
import moment from "moment";

export default {
    components: {
        editableCells,
        editableCell,
        searchArchives,
        FormSearchGroup,
        dynamicSearch,
        btnsWrapper,
        AntMenu,
        searchGroupDetail,
        searchGroupHeader
    },
    data () {
        // const rowSelection = {
        //     onSelect: (record, selected, selectedRows) => {
        //         console.log(record, selected, selectedRows)
        //         if (record.id) {
        //             this.bgWorkId = record.id;
        //             this.bgWorkStatus = record.status;
        //         } else {
        //             this.bgWorkId = null;
        //             this.bgWorkStatus = -1;
        //         }
        //     },
        //     selectedRowKeys: this.selectedRowKeysDetails,
        //     onChange (keys, rows) {
        //         console.log(selectedRowKeys)
        //         this.selectedRowKeysDetails = keys;
        //     },
        //     type: 'radio'
        // };

        const personColumns = [
            {
                title: "工号",
                dataIndex: "empNo",
                align: 'center',
                scopedSlots: {
                    customRender: "empNo",
                },
            },
            {
                title: "姓名",
                align: 'center',
                dataIndex: "empName",
                scopedSlots: {
                    customRender: "empName",
                },
            },
            {
                title: "部门",
                align: 'center',
                dataIndex: "officeName",
                scopedSlots: {
                    customRender: "officeName",
                },
            }
        ];
        const columnModal1 = [

            {
                title: "单据编号",
                align: 'center',
                dataIndex: "voucherCode",
                scopedSlots: {
                    customRender: "voucherCode",
                },
            },
            {
                title: "单据日期",
                align: 'center',
                dataIndex: "voucherDate",
                scopedSlots: {
                    customRender: "voucherDate",
                },
            },
            {
                title: "生产车间",
                align: 'center',
                dataIndex: "officeName",
                scopedSlots: {
                    customRender: "officeName",
                },
            },
            {
                title: "预计开工日期",
                align: 'center',
                dataIndex: "expectStartDate",
                scopedSlots: {
                    customRender: "expectStartDate",
                },
            },
        ];
        const columnModal2 = [
            {
                title: "产品编码",
                align: 'center',
                dataIndex: "inventoryCode",
                scopedSlots: {
                    customRender: "inventoryCode",
                },
            },
            {
                title: "产品名称",
                align: 'center',
                dataIndex: "inventoryName",
                scopedSlots: {
                    customRender: "inventoryName",
                },
            },
            {
                title: "规格型号",
                align: 'center',
                dataIndex: "inventorySpecification",
                scopedSlots: {
                    customRender: "inventorySpecification",
                },
            },
            {
                title: "数量",
                align: 'center',
                dataIndex: "baseQuantity",
                scopedSlots: {
                    customRender: "baseQuantity",
                },
            },
            {
                title: "主计量",
                align: 'center',
                dataIndex: "baseUnitName",
                scopedSlots: {
                    customRender: "baseUnitName",
                },
            },
            {
                title: "bom版本",
                align: 'center',
                dataIndex: "bomName",
                scopedSlots: {
                    customRender: "bomName",
                },
            },
            {
                title: "工艺路线",
                align: 'center',
                dataIndex: "processRouteName",
                scopedSlots: {
                    customRender: "processRouteName",
                },
            },
            {
                title: "累计派遣数量",
                align: 'center',
                dataIndex: "cumDispatchQuantity",
                scopedSlots: {
                    customRender: "cumDispatchQuantity",
                },
            },
            {
                title: "剩余可派遣数量",
                align: 'center',
                dataIndex: "surplusNumber",
                scopedSlots: {
                    customRender: "surplusNumber",
                },
            },
            {
                title: "预计开工日期",
                align: 'center',
                dataIndex: "expectStartDate",
                scopedSlots: {
                    customRender: "expectStartDate",
                },
            },
        ];
        return {
            selectedRowKeysDetails: [],//选中的派工明细
            bgWorkId: null,
            bgWorkStatus: -1,
            // rowSelection,
            workFrom: {
                name: null,
                nameId: null,
                nameCode: null,
                startDate: null,
            },
            showWorkModel: false,
            visibleGr: false,
            hederHeight: "",
            actionType: 4,  //动作  1：上一页 2：下一页 3：首页 4：尾页
            orderId: "001",
            voucherState: -1, //派工单状态(什么状态下可以修改 0可以修改,1已经审核)
            showModel: 'order', //派工单标识按钮
            tableShowLoding: false,
            personColumns,
            selectedRowKeys1: [],
            selectedRowKeys2: [],
            selectItemArr11: [],
            selectItemArr12: [],
            modalList: [],
            modalList2: [],
            columnModal1,
            columnModal2,
            visibleProcessing: false,
            searchData: {
                productId: null,
                productName: null,
                officeId: null,
                officeName: null,
                projectId: null,
                projectName: null,
                chargeUserId: null,
                chargeUserName: null,
                crmId: null,
                crmName: null,
                expectStartDateEnd: null,
                expectStartDateStart: null,
                saleOrderCode: null,
                code: null,
                voucherDateEnd: null,
                voucherDateStart: null,
            },
            //----------↓样式----------
            fromStyle: {
                paddingTop: "8px",
            },
            labelCol: {
                span: 10,
            },
            wrapperCol: {
                span: 14,
            },
            editFalse: {
                borderBottom: "1px solid #ded7d7",
            },
            grid2: {
                xs: 24,
                sm: 24,
                md: 12,
                lg: 8,
                xl: 8,
                xxl: 8,
            },
            grid: {
                xs: 24,
                sm: 24,
                md: 12,
                lg: 8,
                xl: 8,
                xxl: 4,
            },
            btn_grid: {
                xs: 2,
                sm: 2,
                md: 2,
                lg: 2,
                xl: 2,
            },
            //----------↑样式----------
            checkType: 3, //物料类型 1:采购 2:销售 3:生产（bom）
            editMask: true,
            isRouterAlive: true,
            dragStartObj: null, //拖动的目标
            dragEndObj: null, //目标位置
            dragStartIndex: null,
            dragEndIndex: null,
            slotWork: ["name", "teamName", 'productionEquipment', 'startDate'],
            timeSlotArr: [{ code: 'startDate', columnType: '日期', onEdit: true }],
            dataSourceWork: [{}, {}, {}, {}, {}, {}, {}],
            thisClickNoEndId: null,
            columnsWork: [
                {
                    title: "状态",
                    dataIndex: "status",
                    align: 'left',
                    show: false,
                    scopedSlots: {
                        customRender: "status",
                    }
                },
                {
                    title: "操作工编码",
                    dataIndex: "empName",
                    align: 'left',
                    show: false,
                    scopedSlots: {
                        customRender: "empName",
                    }
                },
                {
                    title: "操作工姓名",
                    dataIndex: "name",
                    align: 'left',
                    show: true,
                    scopedSlots: {
                        customRender: "name",
                    }
                },
                {
                    title: "班组",
                    align: 'left',
                    show: false,
                    dataIndex: "teamName",
                    scopedSlots: {
                        customRender: "teamName",
                    }
                },
                {
                    title: "工序名称",
                    align: 'left',
                    show: true,
                    dataIndex: "processRouteName",
                    scopedSlots: {
                        customRender: "processRouteDetal",
                    }
                },
                {
                    title: "工序标识",
                    align: 'left',
                    show: false,
                    dataIndex: "workFlag",
                    customRender: (text) => {
                        if (text == 1) {
                            return '首工序';
                        } else if (text == 2) {
                            return '尾工序';
                        } else if (text == 3) {
                            return '中间工序';
                        }
                    },
                },
                {
                    title: "工序号",
                    align: 'left',
                    dataIndex: "workOrder",
                    show: false,
                },
                {
                    title: "检验方式",
                    dataIndex: "inspectMethod",
                    align: 'left',
                    show: false,
                    customRender: (text) => {
                        if (text == 1) {
                            return '免检';
                        } else if (text == 2) {
                            return '过程检验';
                        } else if (text == 3) {
                            return '完工检验';
                        }
                    },
                },
                {
                    title: "加工方式",
                    align: 'left',
                    show: false,
                    dataIndex: "processMethod",
                    customRender: (text) => {
                        if (text == 1) {
                            return '自制';
                        } else if (text == 2) {
                            return '委外';
                        }
                    },
                },
                {
                    title: "生产设备",
                    align: 'left',
                    show: false,
                    dataIndex: "productionEquipment",
                    scopedSlots: {
                        customRender: "productionEquipment",
                    }
                },
                {
                    title: "质检标准",
                    align: 'left',
                    show: false,
                    dataIndex: "qualityStandard",
                },
                {
                    title: "工艺要求",
                    align: 'left',
                    show: false,
                    dataIndex: "processRequire",
                },
                {
                    title: "开工日期",
                    align: 'left',
                    show: true,
                    dataIndex: "startDate",
                    scopedSlots: {
                        customRender: "startDate",
                    }
                },
                {
                    title: "完工日期",
                    align: 'center',
                    show: false,
                    dataIndex: "endDate",
                },
                {
                    title: "合格数量",
                    align: 'right',
                    show: false,
                    dataIndex: "cumQualifiedQuantity",
                    customRender: (text) => {
                        return this.$numberFormat(text);
                    }
                },
                {
                    title: "不合格数量",
                    align: 'right',
                    show: false,
                    dataIndex: "cumUnqualifiedQuantity",
                    customRender: (text) => {
                        return this.$numberFormat(text);
                    }
                },
                {
                    title: "返工数量",
                    align: 'right',
                    show: false,
                    dataIndex: "cumReworkQuantity",
                    customRender: (text) => {
                        return this.$numberFormat(text);
                    }
                },
            ],

            customClick: (record, index) => {
                return {
                    on: {
                        // contextmenu: (e) => {
                        //   //右键事件
                        //   e.preventDefault();
                        //   if (index <= this.dataSource.length) {
                        //     this.openMenu(e);
                        //     console.log("右键点击的", index);
                        //     this.thisClickId = index;
                        //     // this.thisClickRecord = record;
                        //   }
                        // },
                    },
                };
            },
            customTable: (record, index) => {
                return {
                    on: {
                        click: (e) => {
                            this.mouseIndex = record.id;
                            this.orderId = record.id;
                            this.voucherState = record.examineStatus;
                            this.nowRecord = record;
                            this.getDetails(record);
                        },
                    },
                };
            },
            listData: [],
            mouseIndex: null,
            orderId: null,
            nowRecord: [],
            pagination: {
                size: "small",
            },
            editColumnArraya: ["pickingProcedureName", "warehouseName", "plannedQuantity", "lossRate", "lossQuantity"],//可编辑列名
            dataSource: [],//数据      
            columns: [
                //表头  
                {
                    title: "物料编码",
                    dataIndex: "inventoryCode",
                    align: 'center',
                    show: false
                },
                {
                    title: "物料名称",
                    dataIndex: "inventoryName",
                    align: 'center',
                    show: false
                },
                {
                    title: "规格型号",
                    dataIndex: "inventorySpecification",
                    align: 'center',
                    show: false
                },
                // {
                //   title: "批号",
                //   dataIndex: "barCode",
                //   align:'center'
                // },
                {
                    title: "领料工序",
                    dataIndex: "pickingProcedureName",
                    align: 'center',
                    show: false,
                    scopedSlots: {
                        customRender: "pickingProcedureName",
                    },
                },
                {
                    title: "预出仓库",
                    dataIndex: "warehouseName",
                    align: 'center',
                    show: false,
                    scopedSlots: {
                        customRender: "warehouseName",
                    },
                },
                {
                    title: "主计量",
                    dataIndex: "baseUnitName",
                    align: 'center',
                    show: false
                },
                {
                    title: "计划数量",
                    dataIndex: "plannedQuantity",
                    align: 'center',
                    show: true,
                    scopedSlots: {
                        customRender: "plannedQuantity",
                    },
                },
                {
                    title: "需要数量",
                    dataIndex: "requireQuantity",
                    align: 'center',
                    show: false,
                },
                {
                    title: "损耗数量",
                    dataIndex: "lossQuantity",
                    align: 'center',
                    show: true,
                    scopedSlots: {
                        customRender: "lossQuantity",
                    },
                },
                {
                    title: "损耗率（%）",
                    dataIndex: "lossRate",
                    align: 'center',
                    show: true,
                    scopedSlots: {
                        customRender: "lossRate",
                    },
                },
                // {
                //   title: "换算率",
                //   dataIndex: "unitExchangeRate",
                //   align: 'center'
                // },
                // {
                //   title: "辅计量",
                //   dataIndex: "subUnit",
                //   align: 'center'
                // },
                // {
                //   title: "计划数量2",
                //   dataIndex: "subPlannedQuantity",
                //   align:'center'
                // },
                // {
                //   title: "需要数量2",
                //   dataIndex: "subRequireQuantity",
                //   align:'center'
                // },
                // {
                //   title: "损耗数量2",
                //   dataIndex: "subLossQuantity",
                //   align:'center'
                // },
                {
                    title: "可用量",
                    dataIndex: "availableQuantity",
                    align: 'center',
                    show: false,
                },
                {
                    title: "现存量",
                    dataIndex: "existingQuantity",
                    align: 'center',
                    show: false,
                },
                {
                    title: "累计领用数量",
                    dataIndex: "cumPickQuantity",
                    align: 'center',
                    show: false,
                },
                {
                    title: "累计退料数量",
                    dataIndex: "cumRetQuantity",
                    align: 'center',
                    show: false,
                },
                // {
                //   title: "累计退料数量2",
                //   dataIndex: "subCumRetQuantity",
                //   align:'center'
                // },
                // {
                //   title: "累计补料数量",
                //   dataIndex: "cumRepairQuantity",
                //   align:'center'
                // },
                // {
                //   title: "累计领用数量2",
                //   dataIndex: "subCumPickQuantity",
                //   align:'center'
                // },
                // {
                //   title: "累计补料数量2",
                //   dataIndex: "subCumRepairQuantity",
                //   align:'center'
                // },
            ],

            visible: false,
            top: 0,
            left: 0,

            dataSourceNumber: 5, //默认渲染多少行表格数据
            //11111
            dataJson: {
                code: null, //派工单编号
                ProcessingOrderNo: null,//加工单编号
                productionWorkDetailId: null,//加工单明细id
                productionWorkMainId: null,//加工单id
                voucherDate: moment().format('YYYY-MM-DD'),//单据日期
                dispatchDate: moment().format('YYYY-MM-DD'),//派工日期
                saleOrderCode: null,//销售单号
                processRouteName: null,//工艺路线
                bomId: null,//bom id
                bomVersion: null,//bom版本
                processRouteId: null,//工艺路线id
                officeName: null, //车间
                officeId: null,//车间id
                inventoryCode: null, //产品编码
                inventoryName: null, //产品名称
                inventoryId: null,//产品id
                inventorySpecification: null, //规格型号
                baseUnit: null,//单位
                baseQuantity: null,//总下达量
                quantityreleasedThisTime: null,//本次下达量
                completedQuantity: null,//已完成数量
                timesOfRelease: null,//本次下达次数
                expectFinishDate: null,//预计完工日期
                status: null,//状态
                personInCharge: null,//负责人
                personInChargeId: null,//负责人id
                voucherStateText: null//单据状态文字


                // code: null, //派工单编号
                // ProcessingOrderNo: null,//加工单编号
                // orderNumber: null, //订单编号
                // processRoute: null,//工艺路线
                // workshopName: null, //车间
                // inventoryCode: null, //物料编码
                // inventoryName: null, //物料名称
                // inventoryId: null, //物料id
                // inventorySpecification: null, //规格型号
                // productionType: null, //生产类型
                // invalidDate: null, //有效日期
                // versionCode: null, //版本号
                // remarks: null, //描述
                // unitId: null, //计量单位id
                // unitName: null, //计量单位名称
                // status: 1,
                // processRouteDetails: [], //工艺明细
                // remarks: null,
            },
            //物料
            maskArchives: false,
            inventoryDomTop: null,
            inventoryDomRight: null,
            inputVal: null,
            selectedRowKeys: [],
            selectedData: [],
            searchInventoryCode: null, //编码搜索
            searchStatus: "2", //状态搜索


            showTotal: true,//最后一排可编辑（标识）
        };
    },
    created () {

        this.columnsWork.forEach(item => {
            if (item.show) {
                let title = <div><span style="color:red;font-family: SimSun,sans-serif;font-size:14px">*</span>{item.title}</div>
                item.title = title;
            }
        });

        this.columns.forEach(item => {
            if (item.show) {
                let title = <div><span style="color:red;font-family: SimSun,sans-serif;font-size:14px">*</span>{item.title}</div>
                item.title = title;
            }
        })


        //初始化获取加工单 默认尾页
        this.actionType = 4;
        this.getUserOneByCondition();

        // this.tableInit();//初始化表格
        // this.editColumnArray(this.columns);
        // this.getList();//获取工序路线列表
    },

    mounted () {
        this.hederHeight = this.$refs.hederHeight.offsetHeight;
    },

    updated () {
        Controlwidth("route_tb", 50);
        Controlwidth("process_edit_tb", 50);
    },
    watch: {
        visible (value) {
            if (value) {
                document.body.addEventListener("click", this.closeMenu);
            } else {
                document.body.removeEventListener("click", this.closeMenu);
            }
        },
        visibleProcessing () {
            if (this.visibleProcessing == false) {
                this.maskArchives = false;
                this.selectedRowKeys2 = [];
                this.selectedRowKeys1 = [];
            }
        },
    },

    filters: {
        statusFun (val) {
            // 0:进行中 1:中止 10：完工
            if (val == 0) {
                return '进行中'
            } else if (val == 1) {
                return '中止'
            } else if (val == 10) {
                return '完工'
            }

        }
    },

    methods: {
        moment,
        startTimeChange (date, dateString) {
            this.workFrom.startDate = dateString;
        },

        workChange (e) {
            //变更工人
            if (e) {
                this.workFrom.name = e.empName;
                this.workFrom.nameId = e.userId;
                this.workFrom.nameCode = e.empNo;
                this.showWorkModel = false
            }

        },

        handleGrOk () {
            // //1 审核后  才可以变更
            if (!this.workFrom.startDate) {
                this.$message.warning('请选择开工日期');
                return;
            }
            if (!this.workFrom.name) {
                this.$message.warning('请选择工人');
                return;
            }

            let obj = {
                id: this.bgWorkId,
                workerName: this.workFrom.name,
                workerNo: this.workFrom.nameCode,
                workerId: this.workFrom.nameId,
                startDate: this.workFrom.startDate,
            }
            changeWorkId(obj).then(res => {
                if (res.code == 200) {
                    this.visibleGr = false;
                    this.workFrom.name = null;
                    this.workFrom.nameCode = null;
                    this.workFrom.nameId = null;
                    this.workFrom.startDate = null;
                    this.bgWorkId = null;
                    this.$message.success("变更成功！");
                    this.selectedRowKeysDetails = [];
                    //刷新当前数据
                    this.actionType = 4;
                    this.orderId = null;
                    this.getUserOneByCondition();
                }

            })
        },

        handleGrCancel () {
            this.visibleGr = false;
        },

        bgChange (e) {
            if (this.voucherState == 1) {
                // 审核后允许变更
                console.log(this.bgWorkStatus);
                if (this.bgWorkStatus == -1) {
                    this.$message.warning('请选择状态为进行中的数据可变更');
                } else if (this.bgWorkStatus == 0 && this.bgWorkId) {
                    this.visibleGr = true;
                } else if (this.bgWorkStatus == 1) {
                    this.$message.warning('工序已经中止不能更改');
                }
            }
            // e.preventDefault();
            return false;
        },

        getUserOneByCondition () {
            //  type  1.上一页 2.下一页 3.首页 4.尾页
            let obj = {
                actionType: this.actionType,
                currentId: this.orderId || '',//当前记录id
            }
            getOneByCondition(obj).then(res => {
                if (res.code == 200) {
                    this.editMask = true;
                    if (null != res.data.vproductionDispatchMain && "" != res.data.vproductionDispatchMain) {
                        this.dataSourceWork = [];
                        this.selectedRowKeysDetails = [];
                        //有派工单  
                        //状态(0：未审核 1：已审核 2：完工 3 中止)
                        this.voucherState = res.data.vproductionDispatchMain.voucherState;
                        //单据id
                        this.orderId = res.data.vproductionDispatchMain.id;
                        //物料明细表格
                        this.dataSource = [];
                        // res.data.inventoryDetails.forEach(item => {
                        //     item.lossQuantity = item.lossQuantity.toFixed(2);
                        //     this.dataSource.push(item);
                        // });
                        //解决最后一行不能被编辑
                        this.dataSource.push({});
                        //派工明细表格
                        res.data.procedureDetails.forEach(item => {
                            item.productionEquipment = item.equipmentName;
                            item.endDate = item.finishDate;
                            item.processRouteId = item.procedureId;
                            item.processRouteName = item.procedureName;
                            item.nameId = item.workerId;
                            item.name = item.workerName;
                            item.nameCode = item.workerNo;
                            item.officeId = res.data.vproductionDispatchMain.officeId;
                        });
                        if (res.data.procedureDetails.length > 7) {
                            //7内
                            res.data.procedureDetails.forEach((item, index) => {
                                this.dataSourceWork[index] = item;
                            });
                            //7外
                            res.data.procedureDetails.forEach((item, index) => {
                                if (index > 7) {
                                    this.dataSourceWork[index] = item;
                                }
                            });
                        }
                        //等于7
                        if (res.data.procedureDetails.length == 7) {
                            this.dataSourceWork = res.data.procedureDetails;
                        }
                        //小于
                        if (res.data.procedureDetails.length < 7) {
                            res.data.procedureDetails.forEach((item, index) => {
                                this.dataSourceWork[index] = item;
                            });
                        }

                        let object = res.data.vproductionDispatchMain;
                        object.personInChargeId = object.chargeUserId;
                        object.personInCharge = object.chargeUserName;
                        object.quantityreleasedThisTime = object.dispatchInventoryQuantity;
                        object.timesOfRelease = object.dispatchTimes;
                        object.completedQuantity = object.finishInventoryQuantity;
                        object.ProcessingOrderNo = object.productionWorkCode;
                        object.code = object.voucherCode;
                        object.bomVersion = object.bomName;
                        object.baseQuantity = object.totalInventoryQuantity
                        //单据状态（因为input关系没法用filters,故取2个值）
                        //单据状态(0：未审核 1：已审核 9：中止 10：完工 
                        if (object.voucherState == 0) {
                            object.voucherStateText = '未审核';
                        } else if (object.voucherState == 1) {
                            object.voucherStateText = '已审核';
                        } else if (object.voucherState == 9) {
                            object.voucherStateText = '中止';
                        } else if (object.voucherState == 10) {
                            object.voucherStateText = '完工';
                        };

                        this.dataJson = object;
                        // //初始化计算计划数量
                        // this.numsChange(1);
                        //刷新表格
                        this.reload();
                    } else {
                        //没派工单
                        //  type  1.上一页 2.下一页 
                        if (this.actionType == 1) {
                            this.$message.warning('这已经是首张了');
                        } else if (this.actionType == 2) {
                            this.$message.warning('这已经是未张了');
                        }
                    }
                }
            })

        },

        printOrder (e) {
            //打印
            console.log(1, e)
        },

        switchList (e) {
            //第一列
            console.log(2, e)
        },

        submitServer (e) {
            //保存
            console.log(3, e)
            this.submit();
        },
        clickEdit (e) {
            //修改按钮
            this.editMask = false;
        },
        //删除
        deleteOrder (e) {

            let _this = this;
            this.$confirm({
                title: '确认',
                content: <span>您确定要{<span style='color:red;'>删除</span>}该单据吗？</span>,
                onOk () {
                    deleteApi({ id: _this.orderId })
                        .then(res => {
                            if (res.code == 200) {
                                _this.$message.success("删除成功！");
                                //在此请求最后一条
                                _this.actionType = 4;
                                _this.getUserOneByCondition();
                            }
                        })
                },
                onCancel () { },
            });
        },
        getIdByData (e) {
            console.log(6, e)
            this.actionType = 4;
            this.getUserOneByCondition();
        },
        //单据提交
        submitOrder (type) {
            let data = {
                id: this.orderId,
                status: type,//状态 -1:撤回提交,0:提交
            }
            console.log(this.orderId);
            if (!this.orderId) {
                this.$message.warning('该单据未保存不需要提交');
                return;
            }
            if (this.voucherState == -1 && type == -1) {
                this.$message.warning('该单据未提交无需撤回提交');
                return;
            }
            submitOrder(data).then(res => {
                if (res.code === 200) {
                    if (type == 0) {
                        this.$message.success('提交成功');
                        this.voucherState = 0;
                    } else {
                        this.$message.success('撤回提交成功');
                        this.voucherState = -1;

                    }
                    this.getIdByData();
                }
            })
        },
        auditClick1 (e) {
            let obj = {
                id: this.orderId,
                status: e
            }
            examines(obj).then(res => {
                if (res.code === 200) {
                    if (e == 1) {
                        this.$message.success("审核成功");
                        this.voucherState = 1;
                    }
                    if (e == 0) {
                        this.$message.success("弃审成功");
                        this.voucherState = 0;
                    }
                } else {
                    // this.$message.warning(res.message);
                }
            })
        },

        turnThePage (e) {
            //3.首张  1.上一张 2.下一张  4.末张
            this.actionType = e;
            this.getUserOneByCondition();
        },

        //相互换算 
        numsChange (type, cindex) {
            // 计划数量 = 需要数量 + 需要数量 * (损耗率/100)  
            // 计划数量 = 需要数量 + 损耗数量
            // 损耗数量 = 计划数量 - 需要数量
            // 损耗率 =（损耗数量 / 需要数量）* 100
            switch (type) {
                case 1://下达次数改变=>得到新的需求数量
                    let nums = this.dataJson.quantityreleasedThisTime;
                    this.dataSource.forEach(item => {
                        if ('requireQuantity' in item) {
                            let news = item.newRequireQuantity * nums;
                            //算需要数量
                            this.$set(item, 'requireQuantity', parseFloat(news).toFixed(2));
                            //算计划数量
                            let jhNum = item.requireQuantity + (item.requireQuantity * (item.lossRate / 100));
                            this.$set(item, 'plannedQuantity', parseFloat(jhNum).toFixed(2));
                            //算损耗数量
                            let shNum = item.plannedQuantity - item.requireQuantity;
                            this.$set(item, 'lossQuantity', parseFloat(shNum).toFixed(2));
                        }
                    });
                    break;
                case 2://计划数量改变 
                    this.dataSource.forEach((item, index) => {
                        if (cindex == index) {
                            if ('requireQuantity' in item) {
                                // //算需要数量  
                                // let xqNum = item.plannedQuantity / ((item.lossRate / 100) + 1);
                                // this.$set(item, 'requireQuantity', xqNum);
                                // 损耗数量 = 计划数量 - 需要数量
                                let shNum = item.plannedQuantity - item.requireQuantity;
                                this.$set(item, 'lossQuantity', parseFloat(shNum).toFixed(2));
                            }
                        }
                    });
                    break;
                case 3://损耗率改变 需要数量
                    this.dataSource.forEach((item, index) => {
                        if (cindex == index) {
                            if ('requireQuantity' in item) {
                                //算计划数量
                                let jhNum = item.requireQuantity + (item.requireQuantity * (item.lossRate / 100));
                                this.$set(item, 'plannedQuantity', parseFloat(jhNum).toFixed(2));
                                //损耗数量
                                let shNum = item.plannedQuantity - item.requireQuantity;
                                this.$set(item, 'lossQuantity', parseFloat(shNum).toFixed(2)); //向上取证保留2位
                            }
                        }
                    });
                    break;
                case 4://损耗数量改变
                    this.dataSource.forEach((item, index) => {
                        if (cindex == index) {
                            if ('requireQuantity' in item) {
                                //算计划数量
                                let jhNum = item.requireQuantity + (item.requireQuantity * (item.lossRate / 100));
                                this.$set(item, 'plannedQuantity', parseFloat(jhNum).toFixed(2));
                            }
                        }
                    });
                    break;
                default:
                    console.log('判断有问题')
                    break;
            }
            //刷新表格
            this.reload();
        },
        //派工明细表格点击
        dispatchChange (record, index) {
            return {
                on: {
                    contextmenu: (e) => {
                        //右键事件
                        e.preventDefault();
                        console.log("右键点击的", index);
                        // if (index <= this.dataSource.length) {
                        this.openMenu(e);
                        //   console.log("右键点击的", index);
                        this.thisClickId = index;
                        //   // this.thisClickRecord = record;
                        // }
                    },
                },
            };
        },
        handleMenuClick (e) {
            console.log('click', e);
        },
        getListLeafDetailByMother () {
            listLeafDetailByMother({ motherBomId: this.dataJson.bomId, isGetAvailableQuantity: true })
                .then(res => {
                    if (res.code == 200) {
                        if (res.data.length > 0) {
                            this.dataSource = [];
                            res.data.forEach(item => {
                                item.processRouteId = this.dataJson.processRouteId;
                                item.newRequireQuantity = item.requireQuantity;
                                let xyNum = item.requireQuantity;
                                let shnum = item.lossRate;
                                item.plannedQuantity = xyNum + (xyNum * (shnum / 100));
                                let jhNum = item.plannedQuantity;
                                //损耗数量
                                let shNumber = parseFloat(jhNum - xyNum).toFixed(2);
                                item.lossQuantity = shNumber;
                                item.requireQuantity = parseFloat(xyNum).toFixed(2);
                                this.dataSource.push(item);
                            })
                            //初始化计算计划数量
                            this.numsChange(1);

                            //解决最后一行不能编辑
                            this.dataSource.push({});
                            //刷新表格
                            this.reload();
                        } else {
                            this.dataSource = [];
                        }
                    }
                })
        },


        addClick () {
            //2个都要选择
            if (this.selectedRowKeys1.length == 0) {
                this.$message.warning('请选择加工单');
                return;
            }
            if (this.selectedRowKeys2.length == 0) {
                this.$message.warning('请选择加工单明细');
                return;
            }
            this.editMask = false;
            this.orderId = null;
            //赋值 
            //获取派工单编号
            getCode().then(res => {
                if (res.code == 200) {
                    //赋值之前清空所有页面数据
                    this.dataSourceWork = [{}, {}, {}, {}, {}, {}, {}];
                    this.dataSource = [];
                    this.dataJson = {
                        code: null, //派工单编号
                        ProcessingOrderNo: null,//加工单编号
                        productionWorkDetailId: null,//加工单明细id
                        productionWorkMainId: null,//加工单id
                        voucherDate: moment().format('YYYY-MM-DD'),//单据日期
                        dispatchDate: moment().format('YYYY-MM-DD'),//派工日期
                        saleOrderCode: null,//销售单号
                        processRouteName: null,//工艺路线
                        bomId: null,//bom id
                        bomVersion: null,//bom版本
                        processRouteId: null,//工艺路线id
                        officeName: null, //车间
                        officeId: null,//车间id
                        inventoryCode: null, //产品编码
                        inventoryName: null, //产品名称
                        inventorySpecification: null, //规格型号
                        baseUnit: null,//单位
                        baseQuantity: null,//总下达量
                        quantityreleasedThisTime: null,//本次下达量
                        completedQuantity: null,//已完成数量 
                        timesOfRelease: null,//本次下达次数
                        expectFinishDate: null,//预计完工日期
                        status: null,//状态
                        personInCharge: null,//负责人
                        personInChargeId: null,//负责人id
                        voucherStateText: null//单据状态文字
                    };


                    this.dataJson.code = res.data;
                    this.dataJson.ProcessingOrderNo = this.modalList1[this.selectedRowKeys1[0]].voucherCode;
                    this.dataJson.processRouteName = this.modalList2[this.selectedRowKeys2[0]].processRouteName;
                    this.dataJson.productionWorkMainId = this.modalList1[this.selectedRowKeys1[0]].id;
                    this.dataJson.saleOrderCode = this.modalList2[this.selectedRowKeys2[0]].saleOrderCode;
                    this.dataJson.productionWorkDetailId = this.modalList2[this.selectedRowKeys2[0]].id;
                    this.dataJson.processRouteId = this.modalList2[this.selectedRowKeys2[0]].processRouteId;
                    this.dataJson.bomVersion = this.modalList2[this.selectedRowKeys2[0]].bomName;
                    this.dataJson.bomId = this.modalList2[this.selectedRowKeys2[0]].bomId;
                    this.dataJson.officeId = this.modalList1[this.selectedRowKeys1[0]].officeId;
                    this.dataJson.officeName = this.modalList1[this.selectedRowKeys1[0]].officeName;
                    this.dataJson.inventoryCode = this.modalList2[this.selectedRowKeys2[0]].inventoryCode;
                    this.dataJson.inventoryName = this.modalList2[this.selectedRowKeys2[0]].inventoryName;
                    this.dataJson.inventoryId = this.modalList2[this.selectedRowKeys2[0]].inventoryId;
                    this.dataJson.inventorySpecification = this.modalList2[this.selectedRowKeys2[0]].inventorySpecification;
                    this.dataJson.baseUnit = this.modalList2[this.selectedRowKeys2[0]].baseUnit;
                    this.dataJson.baseUnitName = this.modalList2[this.selectedRowKeys2[0]].baseUnitName;
                    this.dataJson.baseQuantity = this.modalList2[this.selectedRowKeys2[0]].baseQuantity;
                    this.dataJson.completedQuantity = this.modalList2[this.selectedRowKeys2[0]].completedQuantity;
                    this.dataJson.companyId = this.modalList2[this.selectedRowKeys2[0]].companyId;
                    //单据状态（因为input关系没法用filters,故取2个值）
                    this.dataJson.voucherState = 0;
                    this.dataJson.voucherStateText = '未审核';

                    //派工明显表格
                    //给每条数据中添加工艺id,向弹窗传递
                    this.dataSourceWork.forEach(item => {
                        item.processRouteId = this.dataJson.processRouteId;
                        item.officeId = this.dataJson.officeId;
                    });

                    //获得bomid 查询明细2表格
                    // this.getListLeafDetailByMother();

                    //根据表格明细查询，timesOfRelease本次下达次数
                    getMaxDispatchTimes({ workDetailId: this.modalList2[this.selectedRowKeys2[0]].id })
                        .then(res => {
                            if (res.code == 200) {
                                this.dataJson.timesOfRelease = res.data + 1;
                            }
                        })

                    //根据工艺id查询工序list
                    setTimeout(() => {
                        agetDetailList({ id: this.dataJson.processRouteId }).then(res => {
                            if (res.code == 200) {
                                if (res.data.length > 0) {
                                    this.dataSourceWork = res.data.map(d => {
                                        let processRouteDetailId = d.id;
                                        delete d.id;
                                        return {
                                            ...d,
                                            processRouteName: d.workName,   //工序名称
                                            processRouteId: d.workId,       //工序ID
                                            processRouteDetailId,           //工艺路线明细ID
                                            // officeId: this.dataJson.officeId,
                                        }
                                    })
                                    console.log("异步请求工艺路线后，派工单明细表：", this.dataSourceWork);
                                }
                            }
                        })

                        this.reload()
                    }, 200)


                    //选中一条明细后赋值本次下达量
                    if (this.selectedRowKeys2.length > 0) {
                        this.dataJson.quantityreleasedThisTime = this.modalList2[this.selectedRowKeys2[0]].baseQuantity - this.modalList2[this.selectedRowKeys2[0]].cumDispatchQuantity;
                    }
                    //新增确认赋值null
                    this.orderId = null;

                    //关闭遮罩层
                    this.editMask = false;
                    this.visibleProcessing = false;
                    this.voucherState = 0;
                    console.log("派工单主表：", this.dataJson);
                }
            })
        },



        onSelectChange1 (index, item) {
            this.selectedRowKeys1 = index;
            this.selectItemArr11 = item;
            if (this.selectedRowKeys1.length > 0) {
                this.detailsList2(this.selectItemArr11[0].id);
            }
        },

        onSelectChange2 (index, item) {
            this.selectedRowKeys2 = index;
            this.selectItemArr12 = item;
        },
        //根据加工单ID 查询 未完工 产品明细
        detailsList2 (id) {
            listNotDispatchedDetail({ mainId: id })
                .then(res => {
                    if (res.code == 200) {
                        //赋值之前清空
                        this.modalList2 = [];
                        if (res.data.length > 0) {
                            res.data.forEach(item => {
                                item.surplusNumber = item.baseQuantity - item.cumDispatchQuantity;
                            });
                            this.modalList2 = res.data;
                        } else {
                            this.modalList2 = [];
                        }
                    }
                })
        },


        //表格点击监听
        tableChange1 (record, index) {
            return {
                on: {
                    click: () => {
                        let keys = [];
                        this.thisClickNoEndId = record.id;
                        this.detailsList2(record.id);
                        keys.push(index);
                        this.selectedRowKeys1 = keys;
                    }
                }
            }
        },

        //表格点击监听
        tableChange2 (record, index) {
            return {
                on: {
                    click: () => {
                        let keys = [];
                        keys.push(index);
                        this.selectedRowKeys2 = keys;
                    }
                }
            }
        },

        searchGroup () {
            //搜索组件的显示
            this.$nextTick(() => {
                this.$refs.employeesRef.showModal();
                this.styleProcess = { "position": "relative", "z-index": 75 };
                this.styleOffice = { "position": "relative", "z-index": 50 };
            })
        },
        searchBackData (record) {
            this.$refs.employeesRef.closeSearch();
            this.dataJson.personInChargeId = record.id;
            this.dataJson.personInCharge = record.name;
        },



        setValueTips (data) {
            if (data.codesName == 'office') {
                this.searchData.officeId = data.id;
                this.searchData.officeName = data.name;
            } else if (data.codesName == 'project') {
                this.searchData.projectId = data.id;
                this.searchData.projectName = data.name;
            } else if (data.codesName == 'employees') {
                this.searchData.chargeUserId = data.id;
                this.searchData.chargeUserName = data.name;
            } else if (data.codesName == 'crm') {
                this.searchData.crmId = data.id;
                this.searchData.crmName = data.crmName;
            }
        },

        handleSearch1 (n) {
            this.$refs[`${n}`].showModal();
        },

        onChangeDate1 (e, v, type) {
            if (type == 1) {
                this.searchData.voucherDateEnd = v[0];
                this.searchData.voucherDateStart = v[1];
            } else {
                this.searchData.expectStartDateEnd = v[0];
                this.searchData.expectStartDateStart = v[1];
            }
        },


        searchBillsWork (type) {
            this.tableShowLoding = true;
            listNotFinishMain()
                .then(res => {
                    if (res.code == 200) {
                        if (res.data.length > 0) {
                            this.modalList1 = [];
                            res.data.forEach(item => {
                                this.modalList1.push(item)
                            })
                        } else {
                            this.modalList1 = [];
                        }
                        this.reload();
                    }
                    if (type) this.visibleProcessing = true;
                    this.tableShowLoding = false;
                });
        },

        newForecast () {
            //弹窗打开之前清空详情表格,选中项
            this.modalList2 = [];
            this.selectItemArr11 = [];
            this.selectItemArr12 = [];
            //获取车间数据
            let apiUrl = '/system/office/page';
            let Data = { current: 1, size: 10, key: '' };
            getAction(apiUrl, Data)
                .then(res => {
                    if (res.code == 200) {
                        if (res.data.records.length > 0) {
                            this.searchData.officeName = res.data.records[0].officeName;
                            this.searchData.officeId = res.data.records[0].id;
                            //调用搜索请求
                            this.searchBillsWork(true);
                        } else {
                            this.visibleProcessing = true;
                        }
                    }
                })
        },

        cancel () {
            this.visibleProcessing = false;
            this.maskArchives = false;
        },

        ok () {
            this.visibleProcessing = false;
            this.maskArchives = false;
        },

        // tableInit () {
        //   for (let i = 0; i < this.dataSourceNumber; i++) {
        //     this.dataSource.push({});
        //   }
        //   this.reload();
        //   console.log(this.dataSource);
        // },
        reload () {
            //强制刷新表格
            this.isRouterAlive = false;
            this.$nextTick(function () {
                this.isRouterAlive = true;
            });
        },
        newProcess () {
            //新增（初始化数据）
            this.dataSource = [];
            this.mouseIndex = null;
            this.editMask = false;
            this.tableInit();
            this.dataJson = {
                status: 1,
            };
            this.orderId = null;
            this.voucherState = 0;
        },
        openMenu (e) {
            //显示右键菜单
            var x = e.pageX - 250;
            var y = e.pageY - 40;
            this.top = y;
            this.left = x;
            this.visible = true;
        },
        closeMenu () {
            //隐藏右键菜单
            this.visible = false;
        },
        handleAdd () {
            //新增数据
            // const { count, dataSourceWork } = this;
            const newData = {};
            this.$nextTick(() => {
                this.dataSourceWork.splice(this.dataSourceWork.length, 0, newData);
            });
            console.log("新增行：", this.dataSourceWork);
        },
        handleDelete () {
            //删除整行
            let _this = this;
            let numberId = this.thisClickId;
            this.$confirm({
                title: "确认",
                content: (
                    <span>
                        您确定要 {<span style="color:red;"> 删除 </span>}该记录吗？{" "}
                    </span>
                ),
                onOk () {
                    let dataSourceWork = JSON.parse(JSON.stringify(_this.dataSourceWork));
                    if (dataSourceWork.length > _this.dataSourceNumber) {
                        //大于规定行数(删除)
                        _this.dataSourceWork = dataSourceWork.filter(
                            (item, index) => index !== numberId
                        );
                    } else {
                        _this.$message.warning("抱歉,小于5条不能删除");
                        // //小于规定行数(清空)
                        // for (let i = 0; i < dataSourceWork.length; i++) {
                        //   if (i === numberId) {
                        //     for (const key in dataSourceWork[i]) {
                        //       if (key != "number") {
                        //         dataSourceWork[i][key] = "";
                        //       }
                        //     }
                        //   }
                        // }
                        // _this.dataSourceWork = dataSourceWork;
                    }

                    _this.reload();
                },
                onCancel () { },
            });
        },
        onChangeDate (v, s, index) {
            if (index == 1) {
                this.dataJson.dispatchDate = s;
            } else if (index == 2) {
                this.dataJson.expectFinishDate = s;
            } else if (index == 0) {
                this.dataJson.voucherDate = s;
            }
        },
        onCellChange (indexTable, dataIndex, value) {
            //不同表格赋值
            let dataSource;
            //物料明细表格
            if (dataIndex == "pickingProcedureName" || dataIndex == "warehouseName"
                || dataIndex == "plannedQuantity" || dataIndex == "lossRate" || dataIndex == "lossQuantity") {
                dataSource = [...this.dataSource];
            } else {
                //派工明细表格
                dataSource = [...this.dataSourceWork];
            }

            const target = dataSource.find((item, index) => index === indexTable);
            console.log(target, dataIndex, value, indexTable);

            this.$set(target, dataIndex, value);
            if (value) {
                if (dataIndex == "processRouteDetal") {
                    //工艺要求
                    target["processRequire"] = value.processRequire;
                    //检验方式
                    target["inspectMethod"] = value.inspectMethod;
                    //加工方式
                    target["processMethod"] = value.processMethod;
                    //质检标准
                    target["qualityStandard"] = value.qualityStandard;
                    //工序标识
                    target["workFlag"] = value.workFlag;
                    //工序名称
                    target["processRouteName"] = value.workName;
                    //工序id
                    target["processRouteId"] = value.workId;
                    //工序明细id
                    target["processRouteDetailId"] = value.id;
                } else if (dataIndex == "name") {
                    //操作工姓名
                    target["name"] = value.empName;
                    target["nameId"] = value.userId;
                    target["nameCode"] = value.empNo;
                } else if (dataIndex == "teamName") {
                    //班组
                    target["teamName"] = value.name;
                    target["teamId"] = value.id;
                } else if (dataIndex == "startDate") {
                    target["startDate"] = value.value;
                } else if (dataIndex == "pickingProcedureName") {
                    //工序名称和id
                    target["pickingProcedureName"] = value.workName;
                    target["pickingProcedureId"] = value.workId;
                } else if (dataIndex == "warehouseName") {
                    //预出仓库
                    target["warehouseName"] = value.whName;
                }

                // else if (dataIndex == "plannedQuantity") {
                //     //计划数量
                //     target["plannedQuantity"] = parseFloat(value).toFixed(2);
                //     this.numsChange(2, indexTable);
                // } else if (dataIndex == "lossRate") {
                //     //损耗率
                //     target["lossRate"] = value;
                //     this.numsChange(3, indexTable);
                // } else if (dataIndex == "lossQuantity") {
                //     //损耗数量
                //     target["lossQuantity"] = parseFloat(value).toFixed(2);
                //     this.numsChange(4, indexTable);
                // } 
                else if (dataIndex == 'plannedQuantity') {
                    //计划数量 
                    this.$set(target, dataIndex, value);
                    if (target.plannedQuantity != null && target.requireQuantity != null) {
                        //计算 损耗数量=计划数量-需要数量
                        target.lossQuantity = Number(target.plannedQuantity) - Number(target.requireQuantity);
                    }

                    if (target.lossQuantity != null && target.requireQuantity != null) {
                        //计算  损耗率=（损耗数量/需要数量）*100
                        let losstate = (Number(target.lossQuantity) / Number(target.requireQuantity)) * 100;
                        target.lossRate = losstate.toFixed(2);
                    }
                } else if (dataIndex == 'lossQuantity') {
                    this.$set(target, dataIndex, value);
                    //损耗数量 || 损耗率
                    if (target.lossQuantity != null && target.requireQuantity != null) {
                        //计算  损耗率=（损耗数量/需要数量）*100
                        let losstate = (Number(target.lossQuantity) / Number(target.requireQuantity)) * 100;
                        target.lossRate = losstate.toFixed(2);
                    }
                    if (target.requireQuantity != null && target.lossQuantity != null) {
                        //计算 计划数量=需要数量+损耗数量
                        target.plannedQuantity = Number(target.requireQuantity) + Number(target.lossQuantity);
                    }
                } else if (dataIndex == 'lossRate') {
                    this.$set(target, dataIndex, value);
                    //输入损耗率
                    if (target.lossRate != null && target.requireQuantity != null) {
                        //计算  损耗数量=需要数量*损耗率/100
                        target.lossQuantity = (Number(target.requireQuantity) * Number(target.lossRate)) / 100;
                    }
                    if (target.requireQuantity != null && target.lossQuantity != null) {
                        //计算 计划数量=需要数量+损耗数量
                        target.plannedQuantity = Number(target.requireQuantity) + Number(target.lossQuantity);
                    }
                }


                else if (dataIndex == "productionEquipment") {
                    //生产设备
                    target["productionEquipment"] = value;
                }
            } else {
                target["workCode"] = null;
                target["workId"] = null;
                target["workName"] = null;
                target["processMethod"] = null;
            }

            this.$nextTick(() => {
                // this.dataSource = dataSource;
                console.log("明细数据：");
                //第一条数据工序标识是首工序

                this.reload();
            });
        },
        //列表
        getList (searchArray) {
            let postData = {
                current: 1,
                size: -1,
            };
            if (searchArray) {
                if (Object.keys(searchArray).length > 0) {
                    postData = Object.assign(postData, searchArray);
                }
            }
            list(postData).then((response) => {
                if (response.code === 200) {
                    const { data } = response;
                    const { records, total, current, size } = data;
                    this.listData = records;
                    this.listData.forEach((item) => {
                        item.key = item.id;
                    });
                    //如果有列表数据，选中第一条
                    console.log(this.orderId);
                    if (this.listData.length > 0 && this.orderId == null) {
                        this.mouseIndex = this.listData[0].id;
                        this.orderId = this.listData[0].id;
                        this.voucherState = this.listData[0].examineStatus;
                        this.nowRecord = this.listData[0];
                        this.getDetails(this.listData[0]);
                    }

                    if (this.orderId) {
                        this.listData.forEach((item) => {
                            if (item.id == this.orderId) {
                                this.getDetails(item);
                            }
                        });
                    }
                }
            })
                .catch((error) => { });
        },
        //保存
        submit () {
            //top
            if (!this.dataJson.quantityreleasedThisTime) {
                this.$message.warning("本次下达量必须填写");
                return;
            }

            if (!this.dataJson.dispatchDate) {
                this.$message.warning("请选择派工日期");
                return;
            }
            if (!this.dataJson.voucherDate) {
                this.$message.warning("请选择单据日期");
                return;
            }






            //表格1非空
            let leth = 0;
            let arr = [];
            this.dataSourceWork.forEach(item => {
                if (item.name || item.startDate || item.processRouteName) {
                    arr.push(item);
                } else {
                    leth += 1;
                }
            });

            if (leth == this.dataSourceWork.length) {
                this.$message.warning("抱歉至少填写一条派工明细数据");
                return;
            } else {
                for (let index = 0; index < arr.length; index++) {
                    const item = arr[index];
                    if (!item.name) {
                        this.$message.warning("请选择操作工姓名");
                        return;
                    };
                    if (!item.processRouteName) {
                        this.$message.warning("请选择工序名称");
                        return;
                    };
                    if (!item.startDate) {
                        this.$message.warning("请选择开工日期");
                        return;
                    };
                };
            }


            //表格2非空
            //加了最后一行空表格提交的时候删除最后一行故lenth-1
            let arrData = JSON.parse(JSON.stringify(this.dataSource));
            arrData.splice(arrData.length - 1, 1);
            for (let index = 0; index < arrData.length; index++) {
                const item = arrData[index];
                if (!item.plannedQuantity) {
                    this.$message.warning("请填写计划数量");
                    return;
                };
                if (!item.lossQuantity) {
                    this.$message.warning("请填写损耗数量");
                    return;
                };
                if (item.lossRate !== 0) {
                    if (!item.lossRate) {
                        console.log(item.lossRate, 11)
                        this.$message.warning("请填写损耗率");
                        return;
                    };
                }
            };

            arr.forEach(item => {
                item.equipmentName = item.productionEquipment;
                item.finishDate = item.endDate;
                item.procedureId = item.processRouteId;
                item.procedureName = item.processRouteName;
                item.workerId = item.nameId;
                item.workerName = item.name;
                item.workerNo = item.nameCode;
            });

            let obj = {
                id: this.orderId,
                baseUnit: this.dataJson.baseUnit,//单位
                baseUnitName: this.dataJson.baseUnitName,//单位名称
                chargeUserId: this.dataJson.personInChargeId,// 负责人ID
                chargeUserName: this.dataJson.personInCharge,// 负责人姓名
                companyId: this.dataJson.companyId,// 公司id
                dispatchDate: this.dataJson.dispatchDate,//派工日期
                dispatchInventoryQuantity: this.dataJson.quantityreleasedThisTime,//本次派遣数量
                dispatchTimes: this.dataJson.timesOfRelease,// 派遣次数
                expectFinishDate: this.dataJson.expectFinishDate,//预计完工日期
                finishInventoryQuantity: this.dataJson.completedQuantity,//本次完成数量
                inventoryCode: this.dataJson.inventoryCode,//产品编码
                inventoryId: this.dataJson.inventoryId,// 物料id（产品ID）
                inventoryName: this.dataJson.inventoryName,// 物料名称（产品名称）
                inventorySpecification: this.dataJson.inventorySpecification,// 规格型号
                officeId: this.dataJson.officeId,//生产车间id
                officeName: this.dataJson.officeName,//生产车间名称
                processRouteId: this.dataJson.processRouteId,// 工艺路线id
                processRouteName: this.dataJson.processRouteName,//工艺路线名称
                productionWorkCode: this.dataJson.ProcessingOrderNo,// 加工单号
                productionWorkDetailId: this.dataJson.productionWorkDetailId,// 加工单-明细ID
                productionWorkMainId: this.dataJson.productionWorkMainId,// 加工单ID
                saleOrderCode: this.dataJson.saleOrderCode,//销售单号
                voucherCode: this.dataJson.code,//单据编号
                voucherDate: this.dataJson.voucherDate,//单据日期
                bomId: this.dataJson.bomId,//bom id
                bomName: this.dataJson.bomVersion,//bom name
                totalInventoryQuantity: this.dataJson.baseQuantity, //总下达量
                //物料表格
                // inventoryDetails: arrData,
                //派工表格
                procedureDetails: arr,
            }


            dispatch(obj).then(res => {
                if (res.code == 200) {
                    this.$message.success("保存成功！");
                    //刷新当前数据状态
                    this.actionType = 0;
                    this.getUserOneByCondition();
                }
            })
        },

        removeData () {
            //删除
            if (this.selectedRowKeys.length != 1) {
                this.$message.warning("请选择一条数据");
                return;
            }

            let _this = this;
            this.$confirm({
                title: `是否确认删除工序 "${_this.selectedData[0].name}"`,
                content: "",
                onOk () {
                    remove({
                        id: _this.selectedData[0].id,
                    })
                        .then((response) => {
                            if (response.code === 200) {
                                _this.$message.success("删除成功");
                                _this.selectedRowKeys = [];
                                _this.selectedData = [];
                                _this.newProcess();
                                _this.getList();
                            } else {
                                _this.$message.error(response.message);
                            }
                        })
                        .catch((e) => { });
                },
                onCancel () { },
            });
        },
        handlInputArchives () {
            let w = document.body.clientWidth; //当前可视窗口宽度

            this.maskArchives = true;

            if (w < 1600) {
                this.inventoryDomTop = 240;
            } else {
                this.inventoryDomTop = 195;
            }
        },
        closeArchives () {
            this.maskArchives = false;
        },
        checkArchives (data) {
            this.maskArchives = false;
            //返回值处理
            this.dataJson.inventoryId = data[0][0].id;
            this.dataJson.inventoryCode = data[0][0].inventoryCode;
            this.dataJson.inventoryName = data[0][0].inventoryName;
            this.dataJson.inventorySpecification = data[0][0].inventorySpecification;
            this.dataJson.unitId = data[0][0].unitId;
            this.dataJson.unitName = data[0][0].unitName;
        },
        rowClassName (record, index) {
            return this.thisClickNoEndId == record.id ? "hoverRowCard" : "";
        },
        handleArchiveChange (t) {
            //物料编码搜索
            if (t == 1) {
                this.inputVal = this.dataJson.inventoryCode;
            } else if (t == 2) {
                this.inputVal = this.dataJson.inventoryName;
            }
            this.$refs.searchArchivesRef.inputVal = this.inputVal;
            this.$refs.searchArchivesRef.getData(1);
        },
        onSelectChange (keys, data) {
            this.selectedRowKeys = keys;
            this.selectedData = data;
            console.log(keys, data);
        },
        getDetails (record) {
            this.editMask = true;
            let requestData = {
                id: record.id,
            };
            details(requestData)
                .then((response) => {
                    if (response.code === 200) {
                        record.createDate = "";
                        record.updateDate = "";
                        this.dataJson = JSON.parse(JSON.stringify(record));
                        this.dataSource = JSON.parse(JSON.stringify(response.data));
                        if (this.dataSource.length < this.dataSourceNumber) {
                            for (
                                let i = 0;
                                i < this.dataSourceNumber - response.data.length;
                                i++
                            ) {
                                this.dataSource.push({});
                            }
                        }
                        this.reload();
                    } else {
                        this.$message.error(response.message);
                    }
                })
                .catch((e) => { });
        },
        editClick () {
            this.editMask = false;
        },
        //审核
        auditClick (type) {
            let requestData = {
                id: this.orderId,
                status: type,
            };
            examine(requestData).then((response) => {
                if (response.code === 200) {
                    if (type == 1) {
                        this.$message.success("审核成功");
                        this.getList();
                        this.voucherState = 1;
                    }
                    if (type == 0) {
                        this.$message.success("弃审成功");
                        this.getList();
                        this.voucherState = 0;
                    }
                } else {
                    // this.$message.warning(response.message);
                }
            });
        },
        handleSearch (key, confirm, col) {
            //table搜索
            confirm();
            console.log(key, confirm, col);
            this.searchInventoryCode = key[0];

            let searchText = {
                searchKey: this.searchInventoryCode,
            };
            this.getList(searchText);
        },
        handleReset (clearFilters) {
            clearFilters();
            this.searchInventoryCode = "";
            this.getList();
        },
        handleSearchStatus (key, confirm, col) {
            //状态搜索
            confirm();
            console.log(key, confirm, col);
            // this.searchStatus = key[0];

            let searchText = {
                status: this.searchStatus == "2" ? "" : this.searchStatus,
            };
            this.getList(searchText);
        },
        handleChangeStatus (e, v) {
            console.log(e);
            if (e == "2") {
                this.searchStatus = "";
            }
            this.searchStatus = e;
        },
        //刷新
        syncOrder () {
            this.actionType = 0;
            this.getUserOneByCondition();//获取最新一条数据
            // this.turnThePage(4); 
        },
        handleChangeDetails (keys, rows) {
            this.selectedRowKeysDetails = keys;
            let record = rows[0];
            if (record.id) {
                this.bgWorkId = record.id;
                this.bgWorkStatus = record.status;
            } else {
                this.bgWorkId = null;
                this.bgWorkStatus = -1;
            }
        }
    },
};
</script>
<style lang="less">
    @import '~@/style/purchase/voucher.less';
    .credentials-wrapper {
        padding: 12px 0;
        height: auto;
        overflow-y: auto;
        font-size: 14px;
        .ant-input[disabled] {
            background: #f9f9f9;
            border-bottom: 1px solid rgb(222, 215, 215);
        }
        .ant-form-item {
            margin: 0;
        }

        .mask-archives {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            // background: rgba(220, 53, 69, 0.5);
            background: rgba(0, 0, 0, 0);
            z-index: 2;
        }

        .ant-table-tbody > tr > td {
            cursor: pointer;
        }

        .ant-table colgroup > col.ant-table-selection-col {
            width: 30px;
        }

        .edit-mask-route {
            width: calc(100% - 12px);
            height: 100%;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 800;
            background: rgba(255, 255, 255, 0.1);
        }
    }
    .hoverRowCard {
        background-color: rgba(24, 144, 255, 0.2);
        td {
            color: #222;
        }
    }

    .tabbl {
        .ant-table-wrapper .ant-table-pagination {
            text-align: right !important;
        }
    }

    .order-dynamic-form-wrapper {
        label:not(.form-check-label):not(.custom-file-label) {
            font-weight: normal;
        }

        .ant-form-item-label {
            line-height: 32px;
            height: 32px;
        }

        .ant-form-item-control {
            line-height: 30px;
        }
        .ant-input {
            height: 28px;
        }

        .ant-input[disabled] {
            background: #f9f9f9;
        }
    }

    .atable-edit {
        .ant-table-tbody > tr > td {
            padding: 0px 2px !important;
            overflow: hidden;
        }
    }

    .drag-line-top td {
        border-top: 1px dashed #1890ff;
    }

    .drag-line-bottom td {
        border-bottom: 1px dashed #1890ff !important;
    }

    .ant-popover-arrow {
        border-right-color: gray !important;
        border-bottom-color: gray !important;
    }
    .ant-popover-inner {
        border: 1px solid gray !important;
    }
    .divFixed {
        width: calc(100% - 45px);
        height: 100%;
        position: absolute;
        z-index: 11111;
        top: 0;
    }
</style>
